import { t } from 'i18next'
import { MeetingInfo } from '@/pages/index/ManageList/interfaces/meeting'
import dayjs from '@/plugins/dayjs'
import { FetchMeetingListItem, FetchSimpleMccInfo } from './interface'

export const transMeetingList = (list: FetchMeetingListItem[]) => {
	return list.map((param) => ({
		cascadeMeeting: param.cascade_meeting ? true : false,
		confType: param.conf_type ?? 1,
		duration: param.duration ?? '',
		e164: param.conf_id ?? '',
		encryptedType: param.encrypted_type ?? 0,
		maxJoinedMt: param.max_join_mt,
		meetingCategory: param.conf_category ?? 0,
		meetingMoid: param.meeting_moid ?? '',
		meetingName: param.name ?? '',
		meetingRoom: param.meeting_room ? param.meeting_room : [],
		mt: param.mt
			? param.mt.map((item) => ({
					moid: item.account ?? '',
					accountType: item.account_type ?? '',
					name: item.name ?? '',
					portrait32: item.portrait32 ?? '',
			  }))
			: [],
		mtSize: param.mt_size ?? '',
		organiger: param.creator?.name ?? '',
		organigerExtNum: param.creator?.telephone ?? '',
		organigerMobile: param.creator?.mobile ?? '',
		permanentMeeting: param.duration == 0 ? 1 : 0,
		quantumEncryption: param.quantum_encryption ?? 0,
		startTime: param.start_time ? dayjs(param.start_time).format('YYYY-MM-DD HH:mm:ss') : '',
		state: param.state,
		superMtNum: param.enable_audience ?? 0,
	}))
}
export const transSimpleMccInfo = (data: FetchSimpleMccInfo): MeetingInfo => ({
	subject: data.name ?? '',
	vmrName: data.vmr_name ?? '',
	beginTime: data.start_time ? dayjs(data.start_time).format('YYYY-MM-DD HH:mm') : '',
	endTime: data.end_time ? dayjs(data.end_time).format('YYYY-MM-DD HH:mm') : '',
	duration: String(data.duration) ?? '0',
	e164: data.conf_id ?? '',
	onlineNum: data.online_num ?? 0,
	totalNum: data.total_num ?? 0,
	meetingRate: data.video_formats?.[0]?.bitrate ? getMeetingRate(data.video_formats[0].bitrate) : '2M',
	meetingResolution: getMeetingResolution(data.video_formats?.[0]?.resolution),
	cloudMode: 1 /**私有云公有云平台暂无 */,
	cloudModelType: 1 /**私有云公有云平台暂无 */,
	doubleFlowLimit: data.dual_mode ? String(data.dual_mode) : '0',
	liveUrl: data.live_url || '',
	confType: data.conf_type,
	superMtNum: data.enable_audience || 0,
	encryptionType: data.encrypted_type || 0,
	createdBy: {
		name: data.creator?.name || '',
	},
	meetingResourceVO: {
		id: 9,
		key: 'large_conference',
		multi: 192,
		name: t('192方'),
		resolution: '',
		totalCount: 10000,
		usedCount: 0,
	},
})

const getMeetingRate = (rate: number) => {
	if (rate % 1024 === 0) {
		return rate / 1024 + 'M'
	}
	return String(rate)
}

const getMeetingResolution = (resolute: number) => {
	switch (resolute) {
		case 1:
			return 'QCIF'
		case 2:
			return 'CIF'
		case 3:
			return '4CIF'
		case 12:
			return '720P'
		case 13:
			return '1080P'
		case 14:
			return 'WCIF'
		case 15:
			return 'W4CIF'
		case 16:
			return '4k'
		default:
			return '1080P'
	}
}
